<?php
namespace Admin\Controller;


class CategoryController extends AdminController{
    public function index(){
        $pid = I('get.pid',0);
        $category = D('Category','Service');
        $data = $category->GetCategoryByPid($pid,$display = null);
        $this->assign('title','文章分类');
        $this->display();
    }
    public function AddCategory(){
        $category = D('Category','Service');
        
        if($_POST['pid']!=''){
            $res = $category->AddCategory();
            if(!$res['flag']){
                $this->error($res['msg']);
            }
            $this->redirect('index');
        }
        $data = $category->GetCategoryByPid(0);
        $this->assign('data',$data);
        $this->assign('title','新增分类');
        $this->display();
    }
    public function GetCategoryByPid(){
        $pid = I('get.pid');
        $category = D('Category','Service');
        $data = $category->GetCategoryByPid($pid);
        $this->ajaxReturn($data);
    }

    public function EditCategory(){
        $id = I('get.id');
        $Category = D('Category','Service');
        $data = $Category->GetCategoryById($id);
        $this->assign('data',$data);
        $this->display();
    }
    public function SaveCategory(){
        $Category = D('Category','Service');
        $res = $Category->EditCategory();
        if(!$res){
            $this->error('提交失败',U('EditCategory'));return;
        }
        $this->redirect('index');
    }
}